package cn.gotom.svg;

import java.io.File;
import java.net.URL;

/**
 * SVG图形接口工厂
 * 
 * 
 * @author <a href="mailto:peixere@qq.com">裴绍国</a>
 * @version 2013-09-29
 */
public abstract class SVGFactory
{
	/**
	 * 根据配置建立接口的实现
	 * 
	 * @return SVG图形接口
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * @throws ClassNotFoundException
	 */
	public static SVG createSVG() throws InstantiationException, IllegalAccessException, ClassNotFoundException
	{
		return (SVG) Class.forName("com.valwell.svg.salamander.SalamanderPanel").newInstance();
	}

	public static String getDomainPath(Class<?> clazz)
	{
		String domainPath = "";
		URL url = clazz.getClassLoader().getResource("");
		if (url != null)
		{
			domainPath = url.getPath();
		}
		if (domainPath.isEmpty() || domainPath.equals("/"))
		{
			domainPath = clazz.getProtectionDomain().getCodeSource().getLocation().getPath();
			File file = new File(domainPath);
			if (!file.isDirectory())
			{
				domainPath = domainPath.substring(0, domainPath.length() - file.getName().length());
			}
		}
		if (domainPath.endsWith("/"))
		{
			domainPath = domainPath.substring(0, domainPath.length() - 1);
		}
		return domainPath;
	}
}
